/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package systole.view.crud.comparatives;

import systole.exceptions.ExceptionDAO;
import systole.utils.ImageUtils;
import systole.view.crud.controller.ControllerEntityView;
import systole.view.crud.tableModels.ComparativeTableModel;
import systole.view.messages.EntityDescriptions;
import systole.view.utils.ErrorDialog;

/**
 *
 * @author jmj
 */
public class ControllerComparativeView extends ControllerEntityView{


    @SuppressWarnings("unchecked")
    public ControllerComparativeView() throws ExceptionDAO{
        super();
        this.entityList = this.facadeDB.getComparativeBroker().getAllComparatives();
        this.tableModel = new ComparativeTableModel(this.entityList);
        this.entityName = EntityDescriptions.OBSERVATION;
        this.pluralEntity =EntityDescriptions.OBSERVATIONS;
        this.controllerEntityEdition = new ControllerComparativeEdition();
    }



    @Override
    protected boolean canDeleteEntity() {
        return false;
    }

    @Override
    protected void loadIconOnForm() {
        this.entities.setIconImage(ImageUtils.buildImage("resources/icons/comparative/comparative16.png"));
        this.entities.getJXEntityHeader().setIcon(ImageUtils.buildIcon("resources/icons/comparative/comparative32.png"));
    }

    @Override
    public void refreshList() {
         try {
            this.entityList = this.facadeDB.getComparativeBroker().getAllComparatives();
            this.tableModel.refreshList(this.entityList);
            this.entities.getjTableEntities().setModel(this.tableModel);
        } catch (ExceptionDAO ex) {
            this.facadeDB.refreshSession();
            ErrorDialog.showError(this.entities, ex.getMessage());
        }
        this.entities.getjTableEntities().revalidate();
    }
}
